import "package:flutter/material.dart";

// 推荐卡片通用布局
class RecommendItemContentWidget extends StatelessWidget {
  final String imageUrl; //图片地址
  final Widget? imageBottomBar; //图片下方信息
  final String title; //标题
  final Widget? footer; //底部来源信息
  final int titleMaxLine; //标题最大行数
  final Function? onTap;
  const RecommendItemContentWidget({
    super.key,
    required this.imageUrl,
    this.imageBottomBar,
    required this.title,
    this.footer,
    this.titleMaxLine = 2,
    this.onTap,
  });
  @override
  Widget build(BuildContext context) {
    return Material(
      color: Colors.white,
      child: Ink(
        child: InkWell(
          onTap: () {
            onTap?.call();
          },
          splashColor: Colors.black12, // 添加点击水波纹颜色
          highlightColor: Colors.black12, // 添加长按高亮颜色
          splashFactory: InkSparkle.splashFactory, //波纹效果
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.stretch,
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Stack(
                alignment: Alignment.bottomCenter,
                children: [
                  AspectRatio(
                    aspectRatio: 4 / 3,
                    child: Ink.image(
                      width: double.infinity,
                      height: 100,
                      image: AssetImage(imageUrl),
                      fit: BoxFit.cover,
                    ),
                  ),
                  imageBottomBar != null
                      ? Container(
                          width: double.infinity,
                          padding: const EdgeInsets.only(
                              left: 2, bottom: 2, right: 2, top: 6),
                          decoration: const BoxDecoration(
                            gradient: LinearGradient(
                                begin: Alignment.bottomCenter,
                                end: Alignment.topCenter,
                                colors: [
                                  Color.fromARGB(150, 0, 0, 0),
                                  Color.fromARGB(100, 0, 0, 0),
                                  Color.fromARGB(50, 0, 0, 0),
                                  Color.fromARGB(0, 0, 0, 0),
                                ]),
                          ),
                          child: imageBottomBar,
                        )
                      : const SizedBox(),
                ],
              ),
              Expanded(
                flex: 1,
                child: Container(
                  padding: const EdgeInsets.all(8),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.stretch,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Padding(
                        padding: const EdgeInsets.only(top: 2, bottom: 6),
                        child: Text(
                          title,
                          maxLines: titleMaxLine,
                          overflow: TextOverflow.ellipsis,
                        ),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        crossAxisAlignment: CrossAxisAlignment.end,
                        children: [
                          Expanded(
                            flex: 1,
                            child: footer ?? const SizedBox(),
                          ),
                          const Icon(
                            Icons.more_vert_sharp,
                            color: Colors.black45,
                            size: 18,
                          )
                        ],
                      )
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
